package org.qiancizhan.UI;

import org.qiancizhan.Controller.WordController;
import org.qiancizhan.Model.POJO.WordPOJO;
import org.qiancizhan.Utils.UIFormatUtli;

import java.util.List;
import java.util.Scanner;

public class SearchUI {
    private static final Scanner sc = new Scanner(System.in);
    private static final WordController wordController = new WordController();
    public static void disConnectionMenu(){
        System.out.println("本地单词查询，可以输入中英文，或者模糊查询");
        while(true){
            System.out.println("请输入单词\t0.退出搜索");
            String input = sc.nextLine().trim();
            if(input.equals("0")) {
                System.out.println("退出搜索");
                return;
            }
            List<WordPOJO> searchResults = wordController.getWordInfo(input);
            if(searchResults == null || searchResults.isEmpty()){
                System.out.println("没有找到该单词");
                continue;
            }
            System.out.println(UIFormatUtli.HR);
            for(WordPOJO wordPOJO : searchResults){
                System.out.println(wordPOJO.getWord());
                System.out.println(wordPOJO.getTranslate());
                System.out.println(UIFormatUtli.HR);
            }
            System.out.println(String.format("搜索结果共%d个",searchResults.size()));
        }
    }
}
